﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;

namespace BaoJian.e.mn
{
    public partial class forgetPwdApp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void SubmitFinished_Click(object sender, ImageClickEventArgs e)
        {
            MembershipUserCollection collection = Membership.FindUsersByEmail(ZGAccount.Value);
                        
            if (collection.Count > 0)
            {
                //Send a mail
                Step1.Visible = false;
                Step2.Visible = true;
                BoxForgetPassword1.Visible = false;
                BoxForgetPassword2.Visible = true;
                MembershipUser user = collection[Membership.GetUserNameByEmail(ZGAccount.Value)];
                string newPWD = user.GetPassword();
                
                SendMail("lyq628@163.com", ZGAccount.Value, "smtp.163.com", 25, false, "lyq628", "gaotian", "取回密码", "");
 
            }
            else
            {
                AlertBox.Visible = true;
            }
        }

        private static void SendMail(string fromAddress, string toAddresses, string smtpAddress, int smtpPort, bool isSSL, string username, string password, string subject, string body)
        {
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(fromAddress);
            //foreach (string thisAdd in toAddresses)
            //{
            mail.To.Add(new MailAddress(toAddresses));
            //}
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient(smtpAddress);
            smtp.Port = smtpPort;
            smtp.Timeout = int.MaxValue;
            smtp.EnableSsl = isSSL;
            smtp.Credentials = new System.Net.NetworkCredential(username, password);
            smtp.Send(mail);
        }


    }
}
